package com.exercise.utils;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Description: 动态代理类
 * @Date: 2019/11/14 18:00
 * @author: xfei
 */
public class CommonInvocationHandler implements InvocationHandler {

    Object obj;

    /**
     *
     * @param obj 被代理对象
     * @exception: 设置被代理对象
     * @date: 2019/11/14 18:03
     * @return: void
     */
    public void setByProxy(Object obj) {
        this.obj = obj;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        CommonAOPMethod aop = new CommonAOPMethod();
        // 切面方法
        aop.firstMethod();

        Object result = method.invoke(obj, args);

        aop.secondMethod();

        return result;
    }
}
